﻿@model IEnumerable<CoreLims.Models.CoreLims.CommonSupplier>

@{
    Layout = null;
}

<div>
    <div class="input-group">
        <div class="col-3 pr-0" style="display: none">
            <label id="supplierId">@ViewData["SupplierId"]</label>
        </div>
        <div class="col-3 pr-0">
            <span class="input-group-text font-rfs border-radius-noright noRightBorder">供应商代码*</span>
        </div>
        <div class="col-9 pl-0">
            <input id="Supplier-AddSupplier-SupplierCode" class="form-control font-rfs border-radius-noleft" placeholder="必填" />
        </div>
    </div>
    <div class="input-group">
        <div class="col-3 pr-0">
            <span class="input-group-text font-rfs border-radius-noright noRightBorder">供应商名称*</span>
        </div>
        <div class="col-9 pl-0">
            <input id="Supplier-AddSupplier-SupplierName" class="form-control font-rfs border-radius-noleft" placeholder="必填" />
        </div>
    </div>
    <div class="input-group">
        <div class="col-3 pr-0">
            <span class="input-group-text font-rfs border-radius-noright noRightBorder">供应商类型*</span>
        </div>
        <div class="col-9 pl-0 input-group position-relative">
            <select id="Supplier-AddSupplier-Select-Type" class="form-control font-rfs border-radius-noleft" style="width:90%" onchange="selectOnchang(this)">
                @foreach (var item in Model)
                {
                    <option>@item.SupplierType</option>
                }
            </select>
            <div class="col-11 pl-0 input-group position-absolute float-left"><input id="Supplier-AddSupplier-Input-Type" class="form-control font-rfs border-radius-noleft noRightBorder" style="width:100%" placeholder="可输入新的类型" /></div>
        </div>
    </div>
    <div class="input-group">
        <div class="col-3 pr-0">
            <span class="input-group-text font-rfs border-radius-noright noRightBorder">地址1</span>
        </div>
        <div class="col-9 pl-0">
            <input id="Supplier-AddSupplier-Address1" class="form-control font-rfs border-radius-noleft" placeholder="可选" />
        </div>
    </div>
    <div class="input-group">
        <div class="col-3 pr-0">
            <span class="input-group-text font-rfs border-radius-noright noRightBorder">地址2</span>
        </div>
        <div class="col-9 pl-0">
            <input id="Supplier-AddSupplier-Address2" class="form-control font-rfs border-radius-noleft" placeholder="可选" />
        </div>
    </div>
    <div class="input-group">
        <div class="col-3 pr-0">
            <span class="input-group-text font-rfs border-radius-noright noRightBorder">国家</span>
        </div>
        <div class="col-9 pl-0">
            <input id="Supplier-AddSupplier-Nation" class="form-control font-rfs border-radius-noleft" placeholder="可选" />
        </div>
    </div>
    <div class="input-group">
        <div class="col-3 pr-0">
            <span class="input-group-text font-rfs border-radius-noright noRightBorder">省份</span>
        </div>
        <div class="col-9 pl-0">
            <input id="Supplier-AddSupplier-Province" class="form-control font-rfs border-radius-noleft" placeholder="可选" />
        </div>
    </div>
    <div class="input-group">
        <div class="col-3 pr-0">
            <span class="input-group-text font-rfs border-radius-noright noRightBorder">城市</span>
        </div>
        <div class="col-9 pl-0">
            <input id="Supplier-AddSupplier-City" class="form-control font-rfs border-radius-noleft" placeholder="可选" />
        </div>
    </div>
    <div class="input-group">
        <div class="col-3 pr-0">
            <span class="input-group-text font-rfs border-radius-noright noRightBorder">邮编</span>
        </div>
        <div class="col-9 pl-0">
            <input id="Supplier-AddSupplier-ZipCode" class="form-control font-rfs border-radius-noleft" placeholder="可选" />
        </div>
    </div>
    <div class="input-group">
        <div class="col-3 pr-0">
            <span class="input-group-text font-rfs border-radius-noright noRightBorder">电话</span>
        </div>
        <div class="col-9 pl-0">
            <input id="Supplier-AddSupplier-Telephone" class="form-control font-rfs border-radius-noleft" placeholder="可选" />
        </div>
    </div>
    <div class="input-group">
        <div class="col-3 pr-0">
            <span class="input-group-text font-rfs border-radius-noright noRightBorder">传真</span>
        </div>
        <div class="col-9 pl-0">
            <input id="Supplier-AddSupplier-Fax" class="form-control font-rfs border-radius-noleft" placeholder="可选" />
        </div>
    </div>
    <div class="input-group">
        <div class="col-3 pr-0">
            <span class="input-group-text font-rfs border-radius-noright noRightBorder">联系人</span>
        </div>
        <div class="col-9 pl-0">
            <input id="Supplier-AddSupplier-Contacts" class="form-control font-rfs border-radius-noleft" placeholder="可选" />
        </div>
    </div>
    <div class="input-group">
        <div class="col-3 pr-0">
            <span class="input-group-text font-rfs border-radius-noright noRightBorder">联系人电话</span>
        </div>
        <div class="col-9 pl-0">
            <input id="Supplier-AddSupplier-ContactTelephone" class="form-control font-rfs border-radius-noleft" placeholder="可选" />
        </div>
    </div>
    <div class="input-group">
        <div class="col-3 pr-0">
            <span class="input-group-text font-rfs border-radius-noright noRightBorder">电子邮件</span>
        </div>
        <div class="col-9 pl-0">
            <input id="Supplier-AddSupplier-Email" class="form-control font-rfs border-radius-noleft" placeholder="可选" />
        </div>
    </div>
    <div class="input-group">
        <div class="col-3 pr-0">
            <span class="input-group-text font-rfs border-radius-noright noRightBorder">公司网址</span>
        </div>
        <div class="col-9 pl-0">
            <input id="Supplier-AddSupplier-Website" class="form-control font-rfs border-radius-noleft" placeholder="可选" />
        </div>
    </div>
    <div class="input-group">
        <div class="col-3 pr-0">
            <span class="input-group-text font-rfs border-radius-noright noRightBorder">备注</span>
        </div>
        <div class="col-9 pl-0">
            <input id="Supplier-AddSupplier-Note" class="form-control font-rfs border-radius-noleft" placeholder="可选" />
        </div>
    </div>
    <div class="text-right">
        <button id="Supplier-AddSupplier-confirm" class="btn btn-primary font-rfs">确定</button>
        <button id="Supplier-AddSupplier-cancel" type="button" class="btn btn-info font-rfs" data-dismiss="modal">取消</button>
    </div>
</div>

<script>
    $("#Supplier-AddSupplier-Select-Type").prepend(new Option("", ""));
    $("#Supplier-AddSupplier-Select-Type").val("");

    var supplierId = $("#supplierId").html();
    if (supplierId != '' && supplierId != null && supplierId != undefined) {
        $.post("GetSupplier", {
            SupplierId: supplierId
        }, function (data) {
            $("#Supplier-AddSupplier-SupplierCode").val(data.supplierCode);
            $("#Supplier-AddSupplier-SupplierName").val(data.supplierName);
            $("#Supplier-AddSupplier-Input-Type").val(data.supplierType);
            $("#Supplier-AddSupplier-Address1").val(data.address1);
            $("#Supplier-AddSupplier-Address2").val(data.address2);
            $("#Supplier-AddSupplier-Nation").val(data.nation);
            $("#Supplier-AddSupplier-Province").val(data.province);
            $("#Supplier-AddSupplier-City").val(data.city);
            $("#Supplier-AddSupplier-ZipCode").val(data.zipCode);
            $("#Supplier-AddSupplier-Telephone").val(data.telephone);
            $("#Supplier-AddSupplier-Fax").val(data.fax);
            $("#Supplier-AddSupplier-Contacts").val(data.contacts);
            $("#Supplier-AddSupplier-ContactTelephone").val(data.contactTelephone);
            $("#Supplier-AddSupplier-Email").val(data.email);
            $("#Supplier-AddSupplier-Website").val(data.website);
            $("#Supplier-AddSupplier-Note").val(data.note);
        });

    }

    function selectOnchang(obj) {
        $("#Supplier-AddSupplier-Input-Type").val($("#Supplier-AddSupplier-Select-Type").find("option:selected").text());
    };

    $("#Supplier-AddSupplier-confirm").click(function () {
        if ($("#Supplier-AddSupplier-SupplierCode").val().length == 0) {
            alert("供应商代码不能为空！");
            $("#Supplier-AddSupplier-SupplierCode").addClass('error-style');
            return false;
        }
        if ($("#Supplier-AddSupplier-SupplierName").val().length == 0) {
            alert("供应商名称不能为空！");
            $("#Supplier-AddSupplier-SupplierName").addClass('error-style');
            return false;
        }
        if ($("#Supplier-AddSupplier-Input-Type").val().length == 0) {
            alert("供应商类型不能为空！");
            $("#Supplier-AddSupplier-Input-Type").addClass('error-style');
            return false;
        }

        var jsonStr = {};
        jsonStr["SupplierCode"] = $("#Supplier-AddSupplier-SupplierCode").val();
        jsonStr["SupplierName"] = $("#Supplier-AddSupplier-SupplierName").val();
        jsonStr["SupplierType"] = $("#Supplier-AddSupplier-Input-Type").val();
        jsonStr["Address1"] = $("#Supplier-AddSupplier-Address1").val();
        jsonStr["Address2"] = $("#Supplier-AddSupplier-Address2").val();
        jsonStr["Nation"] = $("#Supplier-AddSupplier-Nation").val();
        jsonStr["Province"] = $("#Supplier-AddSupplier-Province").val();
        jsonStr["City"] = $("#Supplier-AddSupplier-City").val();
        jsonStr["ZipCode"] = $("#Supplier-AddSupplier-ZipCode").val();
        jsonStr["Telephone"] = $("#Supplier-AddSupplier-Telephone").val();
        jsonStr["Fax"] = $("#Supplier-AddSupplier-Fax").val();
        jsonStr["Contacts"] = $("#Supplier-AddSupplier-Contacts").val();
        jsonStr["ContactTelephone"] = $("#Supplier-AddSupplier-ContactTelephone").val();
        jsonStr["Email"] = $("#Supplier-AddSupplier-Email").val();
        jsonStr["Website"] = $("#Supplier-AddSupplier-Website").val();
        jsonStr["Note"] = $("#Supplier-AddSupplier-Note").val();

        if (supplierId.length == 0) {
            $.post("postAddSupplier", {
                jsonStr: JSON.stringify(jsonStr)
            }, function (data) {
                alert(data);
            });
        } else {
            jsonStr["SupplierId"] = $("#supplierId").html();
            $.post("postUpdateSupplier", {
                jsonStr: JSON.stringify(jsonStr)
            }, function (data) {
                alert(data);
            });
        }
    });

</script>
